<template>
  <div>
    <el-pagination
      @size-change="sizeChange"
      @current-change="currentChange"
      :current-page.sync="currentPage"
      :page-sizes="pageSizes"
      :page-size.sync="pageSize"
      :layout="layout"
      :total="total"
      background>
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    callback: {
      // 获取列表数据方法
      type: Function,
      default() {
        return function () {}
      }
    },
    page: {
      // 当前页
      type: Number,
      default: 1
    },
    pageSizes: {
      // 配置每页显示多少条
      type: Array,
      default: function () {
        return [1, 2, 3, 5, 10, 20, 40, 80, 100]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    size: {
      // 默认每页显示条数
      type: Number,
      default: 10
    },
    total: {
      // 数据总条数
      type: Number,
      default: 0
    }
  },
  data() {
    return {}
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.size
      },
      set(val) {
        this.$emit('update:size', val)
      }
    }
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 分页器事件
    currentChange(val) {
      // this.$emit('update:page', val)
      // console.log('当前页', val)
      this['callback']()
    },
    sizeChange(val) {
      // console.log('页容量', val)
      this.currentPage = 1
      // this.$emit('update:page', 1)
      // this.$emit('update:size', val)
      this['callback']()
    }
  }
}
</script>
<style lang="less" scoped></style>
